package com.yunshang.shoppingmall.entity;

import com.yunshang.shoppingmall.mapper.UserRolePrivilegesMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class LoadUserService implements UserDetailsService {

    @Autowired
    UserRolePrivilegesMapper userRolePrivilegesMapper;

    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
        List<UserRolePrivileges> userRolePrivilegesList =userRolePrivilegesMapper.selectUserRolePrivilegesByUserName(s);
        LoadUser loadUser=null;
        System.out.println("load--------------->"+userRolePrivilegesList.get(0).getAdminName()+"--"+userRolePrivilegesList.get(0).getrName());
        loadUser=new LoadUser(userRolePrivilegesList.get(0).getAdminName(),userRolePrivilegesList.get(0).getPwd(),userRolePrivilegesList.get(0).getrName(),true,true,true, true);
        return loadUser ;
    }
}
